<?php
###############   COPYLEFT GPLv3 LICENSE   ###############
##
## JFX Version 0.2.9
## Website Management Software
## www.jfxcms.com
##
## Copyright 2009 GPLv3 - http://www.opensource.org/licenses/gpl-3.0.html
##
## Anthony Gallon
## oi_antz@hotmail.com
##
## Permission is hereby granted to any person having a copy of this software
## to freely use and modify as required so long as the copyright notices
## and branding remain intact.
##
## Full license details available at http://www.jfxcms.com/license
##
###############   COPYLEFT GPLv3 LICENSE   ###############


$id = get('block');

$block = new JFX_Block;
$block->loadById($id, post('page'), '', false, true);
//if($block->parentid != '') $block->save();

if(trim($block->details['template_id'])!=''){
    $block->loadById($block->details['template_id'], post('page'), 1, false, true);
}


if(is_object($block->object)){
    $content = $block->object->getContent($block->details['id'], $block->details['page_id']);
}else{
    $ids = explode('-', $id);
    if(count($ids)==1 && count(explode('_', $id))==2){
        // a new block!
        $ids = explode('_', $id);
        $moduleKey = $ids[0];
        $action = $ids[1];
        $obj = JFX::registry('JFX_Module_'.$moduleKey);
    }else{
        $ids = explode('-', $id);
        $moduleKey = $ids[2];
        $obj = JFX::registry('JFX_Module_'.$moduleKey);
    }
    if(is_object($obj)){
        $content = $obj->getDefaultContent($action);
    }else{
        $content = '';
    }

}


$SMARTY->_compile_source('JFXAjaxGetBlockContent', $content, $_compiled);
ob_start();
$SMARTY->_eval('?>' . $_compiled);
$content = ob_get_contents();
ob_end_clean();

$template = $block->getTemplate();
if(strstr($template, ':|content|:')!==false) $content = str_replace(':|content|:', $content, $template);

if(get('insertid')!='') $res->id = get('insertid');
else $res->id = $id;
$res->content = $content;

echo json_encode($res);

exit;










